import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import java.util.HashMap;


public class MyXMLHandlerSceneTA extends DefaultHandler{
    protected HashMap v_trajectories;
	protected HashMap intervals = new HashMap();
	protected TimeInterval ti_last;
    String t_last; //name of the last trajectory being analysed
    String value;
    
	public MyXMLHandlerSceneTA (HashMap v_trajectories)
 	{
 	   this.v_trajectories=v_trajectories;    
 	}
  
  
  public void startElement( String namespaceURI, String localName, String qName,
                                           Attributes attr ) throws SAXException 
  {
   
    if(localName.equals("movement")){
    	
    	this.t_last = (String)attr.getValue("name");
        Trajectory t = new Trajectory(t_last);
        this.v_trajectories.put(t_last, t);
        
    }   
    
  }//startElement

  public void endElement (String namespaceURI, String localName, String rawName)
                                                             throws SAXException
  {
    if(localName.equals("beginning") || localName.equals("end")){
    	Trajectory t = (Trajectory) v_trajectories.get(this.t_last);    	
    	t.addZone(value);            	
    }else if(localName.equals("duration")){
    	Trajectory t = (Trajectory) v_trajectories.get(this.t_last);
        t.setMaximunTime(value);        
    }else if(localName.equals("spatial_current_movement") || localName.equals("actor_current_movement") || localName.equals("temporal_current_movement")){
       this.t_last = value;        
    }else if(localName.equals("allowed_region")){
    	Trajectory t = (Trajectory) v_trajectories.get(this.t_last);
    	t.addZoneToSequence(value);        
    }else if(localName.equals("allowed_actor")){
    	Trajectory t = (Trajectory) v_trajectories.get(this.t_last);
        t.addRole(value);
    }else if(localName.equals("interval_name")){
		this.ti_last = new TimeInterval(value);	
	}else if(localName.equals("interval_beginning")){
		this.ti_last.setStart(value);
	}else if(localName.equals("interval_end")){
		this.ti_last.setEnd(value);	
		intervals.put(this.ti_last.getId(), this.ti_last);
	}else if(localName.equals("temporal_interval")){
		Trajectory t = (Trajectory) v_trajectories.get(this.t_last);
		TimeInterval ti = (TimeInterval) intervals.get(value);	
		t.addTimeInterval(ti);
	}           
  }//endElement


  /*
    Los parametros que recibe es la localizacion de los carateres del elemento.
  */
  public void characters (char[] ch, int start, int end) throws SAXException
  {    
    value = new String (ch, start, end);    
    value = value.trim();         
  }//characters

}

